import React,{useReducer} from 'react'
  const initState = (state, action) => {
    console.log(state, action)
    if(action ==='add'){
      return {...state,count:state.count +1}
    }else if(action==='prep'){
      return {count:state.count -1}
    }
    return state
  }
  const second = {count:0,sex:'男'}
export default function App() {
  const [state, dispatch] = useReducer(initState, second)
  return (
    <div>
      <h2>{state.count}</h2>
      <button onClick={()=>dispatch('add')}>加1</button>
      <button onClick={()=>dispatch('prep')}>减1</button>
    </div>
  )
}
